package com.fit.pages.user;

import java.util.List;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.AnonymousAccess;
import com.fit.annotations.ProfessorAccess;
import com.fit.annotations.StudentAccess;
import com.fit.dao.user.UserDAO;
import com.fit.entities.language.Language;
import com.fit.entities.user.User;
import com.fit.pages.ErrorPage;

@AdminAccess
@AnonymousAccess
@ProfessorAccess
@StudentAccess
public class View {

	@Property
	@Persist
	private User user;
	@Inject
	private UserDAO userDAO;
	@InjectPage
	private ErrorPage errorPage;
	@Property
	private List<User> users;
	
	void onActivate() {
		users = userDAO.findAll();
	}

	Object onActivate(Long id) {
		user = userDAO.findByID(id);
		users = userDAO.findAll();

		if (user == null) {
			errorPage.setMessage("Error while trying to view user! ");
			return errorPage;
		}

		return null;

	}

//	Object onActivate(Long id) {
//		user = userDAO.findByID(id);
//		if (user == null) {
//			errorPage.setMessage("Greska prilikom prikaza zapisa korisnika! ");
//			return errorPage;
//		}
//		return null;
//
//	}

}
